package com.southwind.springboottest.repository;

import com.southwind.springboottest.entity.BorrowRecord;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BorrowRecordRepository extends JpaRepository<BorrowRecord, Integer> {
    Optional<BorrowRecord> findByBorrowRecordId(Integer borrowRecordId);
    @Query("SELECT COUNT(b) FROM BorrowRecord b WHERE b.user.id = :userId AND b.returnTime IS NULL")
    Integer countBorrowingByUser(@Param("userId") Integer userId);
}
